local xinxuan = fk.CreateSkill {
  name = "lingling__xinxuan",
}

Fk:loadTranslationTable{
  ["lingling__xinxuan"] = "心悬",
  [":lingling__xinxuan"] = "出牌阶段限一次，你可以弃置一张牌，令一名其他角色视为对你指定的角色使用【杀】，若造成/未造成伤害，"..
  "你视为对使用者/目标使用【推心置腹】。",

  ["#lingling__xinxuan"] = "心悬：弃一张牌，令一名角色视为对另一名角色使用【杀】",
  ["lingling__xinxuan_tip_1"] = "使用者",
  ["lingling__xinxuan_tip_2"] = "目标",
}

xinxuan:addEffect("active", {
  anim_type = "offensive",
  max_phase_use_time = 1,
  card_num = 1,
  target_num = 2,
  prompt = "#lingling__xinxuan",
  target_tip = function(self, _, to_select, selected, _, _, selectable, _)
    if not selectable then return end
    if #selected == 0 or (#selected > 0 and selected[1] == to_select) then
      return "lingling__xinxuan_tip_1"
    else
      return "lingling__xinxuan_tip_2"
    end
  end,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and not player:prohibitDiscard(to_select)
  end,
  target_filter = function(self, player, to_select, selected)
    if #selected < 2 then
      local card = Fk:cloneCard("slash")
      card.skillName = xinxuan.name
      if #selected == 0 then
        return to_select ~= player and to_select:canUse(card, { bypass_distances = true, bypass_times = true })
      else
        return selected[1]:canUseTo(card, to_select, { bypass_distances = true, bypass_times = true })
      end
    end
  end,
  feasible = function (self, player, selected, selected_cards)
    if #selected == 2 and #selected_cards == 1 then
      local card = Fk:cloneCard("slash")
      card.skillName = xinxuan.name
      return selected[1] ~= player and selected[1]:canUseTo(card, selected[2], { bypass_distances = true, bypass_times = true })
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    room:throwCard(effect.cards, xinxuan.name, player, player)
    if effect.tos[1].dead or effect.tos[2].dead then return end
    local use = room:useVirtualCard("slash", nil, effect.tos[1], effect.tos[2], xinxuan.name, true)
    if use and not player.dead then
      if use.damageDealt then
        if not effect.tos[1].dead then
          room:useVirtualCard("ling__sincere_treat", nil, player, effect.tos[1], xinxuan.name)
        end
      else
        if not effect.tos[2].dead and effect.tos[2] ~= player then
          room:useVirtualCard("ling__sincere_treat", nil, player, effect.tos[2], xinxuan.name)
        end
      end
    end
  end,
})

return xinxuan
